<template>
  <a-modal
    title="打印"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
  <template slot="footer">
        <a-button key="back" @click="handleCancel">
          取消
        </a-button>
        <a-button key="submit" type="primary"  @click="handleSubmit">
          打印
        </a-button>
  </template>
  <div class="print"  ref="print">
    <a-row>
      <a-col :span="24" class="title">
       <strong>{{ form.letterhead }}</strong>
      </a-col>
    </a-row>
    <a-row>
      <a-col :span="24" class="title">
       <strong>房间预订单</strong>
      </a-col>
    </a-row>
    <a-row>
      <a-col :span="12" class="ydxx">
       <span>預定房間：{{ roomCode }}</span>
      </a-col>
      <a-col :span="12" class="ydxx">
       <span class="item-end">單據號：{{ ydNo }}</span>
      </a-col>
    </a-row>
    <a-row>
      <a-col :span="12" class="ydxx">
       <span>預定人：{{ reservation }}</span>
      </a-col>
      <a-col :span="12" class="ydxx">
       <span class="item-end">預定時間：{{ collectionDate }}</span>
      </a-col>
    </a-row>
    <div class="main-content">
      <a-row class="dj main-content-item">
        <a-col :span="24" class="ydxx">
          <span>定金：{{ deposit }}元</span>
        </a-col>
      </a-row>
      <a-row class="main-content-item">
        <a-col :span="24" class="ydxx">
          <p>1.若不入住，定金不退</p>
          <p>2.租金入住后，定金不退转</p>
          <p>此房月租金{{ rent }}元，收租周期{{ receiptCycle }}</p>
          <p>最晚入住日：{{ latestDate }}</p>
          <p>{{ remark }}</p>
        </a-col>
      </a-row>
    </div>
      <a-row>
      <a-col :span="8" class="ydxx">
       <span>打印日期：{{ dayinDate }}</span>
      </a-col>
      <a-col :span="8" class="ydxx">
       <span>付款人：</span>
      </a-col>
      <a-col :span="8" class="ydxx">
       <span class="item-end">收款人：{{ form.payee }}</span>
      </a-col>
    </a-row>
  </div>
  </a-modal>
</template>

<script>
  import { busPrintSettingsOne } from '@/api/modular/main/busprintsettings/busPrintSettingsManage'
  import moment from 'moment'
  export default {
    data () {
      return {
        visible: false,
        confirmLoading: false,
        roomCode: '',
        ydNo: '',
        reservation: '',
        collectionDate: '',
        deposit: '',
        rent: '',
        receiptCycle: '',
        latestDate: '',
        dayinDate: moment().format('YYYY-MM-DD'),
        remark: '',
        form: {
          id: '',
          size: '',
          letterhead: '',
          letterheadenable: true,
          customerenable: true,
          titleenable: true,
          payerenable: true,
          payer: '',
          payeeenable: true,
          payee: '',
          remark: ''
        }
      }
    },
    created() {
      this.getData()
    },
    methods: {
      moment,
      // 初始化方法
      edit (record) {
        this.visible = true
        this.roomCode = record.roomCode
        this.ydNo = record.ydNo
        this.reservation = record.reservation
        this.collectionDate = record.collectionDate
        this.deposit = record.deposit
        this.rent = record.rent
        this.receiptCycle = record.receiptCycle
        this.latestDate = record.latestDate
        this.remark = record.remark
      },
      getData () {
        busPrintSettingsOne().then((res) => {
          if (res.code === 200) {
            this.form = res.data
          } else {
            this.$message.error('查詢失敗')//  + res.message
          }
        })
      },
      handleSubmit () {
        this.$print(this.$refs.print) // 使用
        this.handleCancel()
      },
      handleCancel () {
        this.visible = false
      }
    }
  }
</script>
<style scoped>
.print{
  padding: 6px 10px;
}
.title{
  text-align: center;
  tab-size: 20px;
}
.item-end{
  float: right;
}
.main-content{
  margin-top: 10px;
  margin-bottom: 10px;
  border: solid 1px rgb(218, 211, 211);
}
.dj{
  border-bottom: solid 1px rgb(218, 211, 211);
}
.main-content-item{
  padding: 10px;
}
</style>
